<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page language="java" import="com.base.myproject.client.jdbc.*"%>
<%@ page language="java" import="com.base.myproject.server.*"%>
<%@ page language="java" import="com.base.myproject.client.jdbc.DataSet"%>
<%@ page language="java" import="com.base.myproject.server.tools.*,java.util.Calendar,java.math.BigDecimal"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>考勤明细</title>
<%
	Calendar time=Calendar.getInstance();  
	time.clear(); 
	
	String data = request.getParameter("data");
	String level = request.getParameter("level");
	String[] datas = data.split("_");
	
	int year = Integer.parseInt(datas[2]);
	int month = Integer.parseInt(datas[3]);
	int days = 0;
	
	time.set(Calendar.YEAR,year);  
	time.set(Calendar.MONTH,month-1);//Calendar对象默认一月为0   
	days=time.getActualMaximum(Calendar.DAY_OF_MONTH);//本月份的天数
	int weekEnd = 0;
	for (int i=1; i <= days; i++) {
		time.set(Calendar.DATE,i);//Calendar对象默认天为0   
		if (time.get(Calendar.DAY_OF_WEEK) == 7) {
			weekEnd = i;
			break;
		}
		if (time.get(Calendar.DAY_OF_WEEK) == 1) {
			weekEnd = i-1;
			break;
		}
	}
	
	String s_date = datas[0];
	String dep_code = datas[1];

	String sql = "select isnull(period,0) as period,bname,(select employno from bcode_job where a.bcode=bcode_job.bcode) as bcode, ";
	for (int i = 1; i < days + 1; i++) {
		String d = "";
		if (i < 10) {
			d = "0" + String.valueOf(i);
		} else {
			d = String.valueOf(i);
		}
		sql += "isnull(r"
				+ i
				+ ",'') + isnull((select stuff((select '' + value from v_ot where type in('加班','补休') and  bcode=a.bcode and depCode=a.depCode and usedate='"
				+ s_date + "-" + d + "' "
				+ " for xml path('')),1,0,'')),'') as r" + i + ",";
	}
	sql = sql.substring(0, sql.length() - 1);
	sql += " from hr_attendance_schedule as a left join hr_Attendance_ot ot on a.bcode = ot.bcode"
			+ " and a.depcode = ot.depcode and convert(varchar(7),ym,120) = convert(varchar(7),signdate,120) and type = '上月结转' where a.depcode like '"
			+ dep_code + "%' and convert(varchar(7),ym,120)='" + s_date
			+ "'";
	if (!level.equals("")) {
		sql += " and exists (select * from bcode_job where bcode = a.bcode and employlevel in("
				+ level + "))";
	}
	DataSetTool DST = new DataSetTool();
	DataSet result = DST.getDataSet(sql);
	DataSet department = DST
			.getDataSet("select name from systeminfo where id='"
					+ dep_code + "'");
	String workbatchSql = "select batchName,batchNo,bgnTime1,endTime1,bgnTime2,endTime2 from hr_Attendance_workbatch where depCode = '"
			+ dep_code + "'";
	DataSet workbatch = DST.getDataSet(workbatchSql);
%>
</head>
<body>
<p align='center'><font size='4'><b>考勤明细表</b></font></p>
查询年月：<%=s_date%>
部门：<%=department.getValue(0, "name")%><br></br>
<table style="border-collapse: collapse; font-size: 10px;"
	cellspacing="0" cellpadding="0" border="1" width="100%"
	bordercolordark="#CCCCCC" bordercolorlight="#CCCCCC"
	style="border-color:#000000; ">
	<tr bgcolor="#e8e8e0" align="center">
		<td width="45">姓名</td>
		<td width="45">员工编号</td>
		<% for (int i=1; i<=days; i++) { %>
			<td <% if (i%7 == weekEnd || i%7 == (weekEnd + 1)) { %>bgcolor="#e8e8e0"<% } %>><%= i %></td>
		<% } %>
		<td>上月结转数</td>
	</tr>
	<%
		for (int i = 0; i < result.getRowCount(); i++) {
	%>
	<tr style="" align="center">
		<td style="white-space: nowrap;"><%=result.getValue(i, "bname")%></td>
		<td><%=result.getValue(i, "bcode")%></td>
		<% for (int j=1; j<=days; j++) { %>
			<td <% if (j%7 == weekEnd || j%7 == (weekEnd + 1)) { %>bgcolor="#e8e8e0"<% } %>><%=result.getValue(i, "r" + j) == null ? " " : result
						.getValue(i, "r" + j)%></td>
		<% } %>
		<td><%=RPTString2Double.string2String(result.getValue(i, "period"))%></td>
	</tr>
	<%
		}
	%>

</table>
<p></p>
<table style="border-collapse: collapse" cellspacing="0" cellpadding="0"
	border="1" width="100%" bordercolordark="#CCCCCC"
	bordercolorlight="#CCCCCC"
	style="line-height: 150%;border-color:#000000;">
	<%
		for (int i = 0; i < workbatch.getRowCount(); i++) {
			if (i % 4 == 0) {
	%>
	<tr>
		<%
			}
		%>
		<td><%=workbatch.getValue(i, "batchName")%> (<%=workbatch.getValue(i, "batchNo")%>)
		&nbsp;<%=workbatch.getValue(i, "bgnTime1") == null ? ""
						: workbatch.getValue(i, "bgnTime1") + " -"%>
		<%=workbatch.getValue(i, "endTime1") == null ? ""
						: workbatch.getValue(i, "endTime1")%>
		&nbsp;<%=workbatch.getValue(i, "bgnTime2") == null ? "" : ","
						+ workbatch.getValue(i, "bgnTime2") + " -"%>
		<%=workbatch.getValue(i, "endTime2") == null ? ""
						: workbatch.getValue(i, "endTime2")%>
		</td>
		<%
			if ((i + 1) % 4 == 0) {
		%>
	</tr>
	<%
		}
	%>
	<%
		}
	%>
</table>
<br></br>
<p></p>
<p align="center">考勤员:___________________ 部门主管：___________________人力资源部:_________________</p>




</body>
</html>